package com.wings4.school.academicconfiguration
import grails.converters.JSON
class AcademicConfigurationController {

    def index() { }
    def academicYearList(){
        render(view: 'academic_year_list');
    }
    def academicYearCreate(){
        render(view: 'academic_year_create');
    }
    def academicYearSave(){}
    def academicYearEdit(){
        render(view: 'academic_year_edit');
    }
    def academicYearUpdate(){}
    def academicYearJsonData(){
        List<AcademicYear> academicYearList = AcademicYear.findAll();
        List academicYearArrayList = new ArrayList();
        Map<String,String> academicYearMap;
        for (AcademicYear academicYear:academicYearList){
            academicYearMap = new HashMap<String, String>();
            academicYearMap.put("id",academicYear?.id?.toString());
            academicYearMap.put("yearName",academicYear?.academicYearName);
            academicYearMap.put("startTime",academicYear?.startTime?.toString());
            academicYearMap.put("endTime",academicYear?.endTime?.toString());
            academicYearMap.put("status",academicYear?.status?.toString());
            academicYearMap.put("createDate",academicYear?.createdDate?.toString());
            academicYearArrayList.add(academicYearMap);
        }
        if (!params.limit) {
            params.max = 50;
        } else {
            params.max = params.limit;
        }
        int totalCount = academicYearArrayList.size();


        int start = (params.start != null) ? Integer.parseInt(params.start) : 0;
        int limit = (params.limit != null) ? Integer.parseInt(params.limit) : 50;

        render([academicYearList : academicYearArrayList.asList().subList(start, start + limit > academicYearArrayList.size() ? academicYearArrayList.size() : start + limit),totalCount:totalCount] as JSON);
    }

}
